<?php 

/*====================================================
 Author: RooTM
------------------------------------------------------
 Web-site: http://weboss.net/
=====================================================*/

if( ! defined( 'DATALIFEENGINE' ) ) {
	die( "Hacking attempt!" );
}

if( $Messages === false ) {

require_once ENGINE_DIR . '/classes/templates.class.php';

if (!defined('TEMPLATE_DIR')) {
$tpl = new dle_template ( );
$tpl->dir = ENGINE_DIR . '/modules/iChat/template/';
define ( 'TEMPLATE_DIR', $tpl->dir );	
}
 
if($_POST['place'] == "history"){$chat_cfg['sum_msg'] = "9999";}

 $db->query( "SELECT * FROM " . PREFIX . "_iChat ORDER BY date DESC LIMIT 0,{$chat_cfg['sum_msg']}" );

$tpl->load_template ( 'message.tpl' );

while ( $row = $db->get_row() ) {
 	
$color = stristr($chat_cfg['groups_color'], 'group_'.$row['user_group'].':' );
$color = reset(explode(',',$color));
$color = trim(str_replace('group_'.$row['user_group'].':','',$color));

if( $config['allow_alt_url'] == "yes" ) $go_page = $config['http_home_url'] . "user/" . urlencode( $row['author'] ) . "/";
	 else $go_page = "$PHP_SELF?subaction=userinfo&amp;user=" . urlencode( $row['author'] );
			
$author = "<a onclick=\"ShowProfile('" . urlencode( $row['author'] ) . "', '" . $go_page . "'); return false;\" href=\"" . $go_page . "\"><span style=\"color:".$color."\">" . $row['author'] . "</span> </a>";
		
$tpl->set ( '{id}', $row['id'] );
$tpl->set ( '{date}', ShowDate($chat_cfg['format_date'],strtotime($row['date'])) );
$tpl->set ( '{author}', $author );
$tpl->set ( '{name}', $row['author']);
$tpl->set ( '{message}', $row['message'] );
$tpl->set ( '{THEME}', "/engine/modules/iChat/template" );

$tpl->compile ( 'message' );

    }
	
	$db->free();
     $tpl->clear();

$Messages = $tpl->result['message'];

if(!$Messages) {$Messages = $chat_lang['no_messages'];}
     
if($_POST['place'] == "history"){
$Messages = str_replace ( array( 'iChatDelete(' , 'iChatEdit(' ) , array( 'iChatDeleteHistory(' , 'iChatEditHistory(' ) , $Messages );
create_cache( "iChat_history", $Messages, $config['skin'] );
}else{
create_cache( "iChat", $Messages, $config['skin'] );
}

}

$Messages = preg_replace ( "#\\[for_group=(.+?)\\](.*?)\\[/for_group\\]#ies", "check_group('\\1', '\\2')", $Messages );
$Messages = preg_replace ( "#\\[not_for_group=(.+?)\\](.*?)\\[/not_for_group\\]#ies", "check_group('\\1', '\\2', false)", $Messages );

if( $user_group[$member_id['user_group']]['edit_allc'] ) $Messages = preg_replace( "'\[allow_edit\](.*?)\[/allow_edit\]'si", "\\1", $Messages );
      else $Messages = preg_replace ( "'\[allow_edit\](.*?)\[/allow_edit\]'si", "", $Messages );

if( $user_group[$member_id['user_group']]['del_allc'] ) $Messages = preg_replace( "'\[allow_delete\](.*?)\[/allow_delete\]'si", "\\1", $Messages );
      else $Messages = preg_replace ( "'\[allow_delete\](.*?)\[/allow_delete\]'si", "", $Messages );

if( $user_group[$member_id['user_group']]['allow_hide'] ) $Messages = preg_replace( "'\[hide\](.*?)\[/hide\]'si", "\\1", $Messages );
else $Messages = preg_replace ( "'\[hide\](.*?)\[/hide\]'si", "<div class=\"quote\">" . $chat_lang['hide'] . "</div>", $Messages );

if( $member_id['user_group'] == 1 ) $Messages = preg_replace( "'\[admin\](.*?)\[/admin\]'si", "\\1", $Messages );
else $Messages = preg_replace ( "'\[admin\](.*?)\[/admin\]'si", "<div class=\"quote\">" . $chat_lang['admin_hide'] . "</div>", $Messages );

?>
